#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int minFlips(vector<vector<int>>& grid) {
        int n = grid.size();
        int rsame = 0;
        for (int i = 0; i < n; i++)
        {
            int m = grid[i].size();
            for (int j = 0; j < (m + 1) / 2; j++)
            {
                if (grid[i][j] != grid[i][m - j - 1])
                    ++rsame;
            }
        }
        int csame = 0;
        int m = grid[0].size();
        for (int j = 0; j < m; j++)
        {
            for (int i = 0; i < (n + 1) / 2; i++)
            {
                if (grid[i][j] != grid[n - i - 1][j])
                    ++csame;
            }
        }
        return min(rsame, csame);
    }
};